package org.ala.tiktools.generator.mybatis.config.info;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author ala
 * @date 2024-12-30 13:41
 */
public class Generator {
    /**
     *  名称
     */
    protected String name;
    /**
     *  dbms信息
     */
    protected DBMS dbms;
    /**
     *  组件信息
     */
    protected List<Part> parts;


    @SuppressWarnings("unchecked")
	public static Generator build(String name, Map<String, Object> kvs) {
        Generator g = new Generator();
        g.name = name;
        g.setDbms(DBMS.build((Map<String, Object>) kvs.get("dbms")));
        List<Part> parts = new ArrayList<>();
        Map<String, Object> partKvs = (Map<String, Object>) kvs.get("part");
        partKvs.forEach((k,v) -> {
            if (v instanceof Map) {
                Map<String, Object> kv = (Map<String, Object>) v;
                parts.add(Part.build(k, kv));
            }
        });
        g.setParts(parts);
        return g;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public DBMS getDbms() {
        return dbms;
    }

    public void setDbms(DBMS dbms) {
        this.dbms = dbms;
    }

    public List<Part> getParts() {
        return parts;
    }

    public void setParts(List<Part> parts) {
        this.parts = parts;
    }
}
